package day0113

import "math"

/*
dfs？
三层循环？
*/

func threeSumClosest(nums []int, target int) int {
	min := math.MaxInt64
	r := math.MaxInt64
	for i := 0; i < len(nums)-2; i++ {
		for j := i + 1; j < len(nums)-1; j++ {
			for k := j + 1; k < len(nums); k++ {
				if abs(nums[i]+nums[j]+nums[k]-target) < r {
					r = abs(nums[i] + nums[j] + nums[k] - target)
					min = nums[i] + nums[j] + nums[k]
				}
			}
		}
	}
	return min
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
